/**文章详情入口
 * Created by alice on 2016/7/14.
 */
require.config({
    baseUrl:'../js',
    paths:{
        "getData":"Util/getData",
        "config":"common/config",
        "components":"common/components",
        "common":"common/common",
        "jquery":"lib/jquery.min",
        "wx":"lib/jweixin-1.0.0"
    },
    shim : {
        "components": { deps : ["jquery"] }
    },
    urlArgs: "v=" + (new Date()).getTime()//以禁用浏览器缓存,上线后注释掉
});
require(['jquery','getData','config','common','components','wx'],function($,getData,config,common,components,wx){
    var gm=common.gm;
    var token=gm.para.get(window.location.href,"token");
    var contentid=gm.para.get(window.location.href,"favoriteUuid");
    //var getUrl=gm.common.delQueStr(location.href.split('#')[0],'token');
    var getUrl=location.href.split('#')[0];

    delAllCookie();
    //删除cookie中所有定变量函数    
       function delAllCookie(){
            var myDate=new Date();    
            myDate.setTime(-1000);//设置时间    
            var data=document.cookie;    
            var dataArray=data.split("; ");    
            for(var i=0;i<dataArray.length;i++){    
                 var varName=dataArray[i].split("=");    
                 document.cookie=varName[0]+"=''; expires="+myDate.toGMTString();    
            }    
                          
      } 

    /*if(gm.common.isWeiXin()){//判断是否是微信
     /!*$.ajax({
     url: "http://hxq.app3.haoxinqing.cn/app-web/app/v1_6/weixin/signature/getSignature",
     type: "post",
     data:{url:getUrl},
     dataType: "json",
     success: function (data) {
     if (data.code == "2000") {
     getSignMessCollbak(data);
     }
     }
     });*!/
     gm.common.userShare({});//分享调用
     getData.getJson({
     page:"content",
     inter:"getSignature",
     data:{url:getUrl},
     callback:function(data){
     if(data.code=="2000"){
     getSignMessCollbak(data);
     }
     }
     })
     }*/
    /**
     * 微信分享的回调
     * @param data
     */
    /*function getSignMessCollbak(data){
     //微信二次分享
     var d=data.value;
     var appId= d.appid;
     var timestamp= d.timestamp;
     var nonceStr= d.nonceStr;
     var signature= d.signature;
     var title=gm.para.get(window.location.href,"title");
     title = decodeURIComponent(title);
     var imgUrl=window._interfaceImgPath+""+gm.para.get(window.location.href,"img");
     var desc=gm.para.get(window.location.href,"desc");
     desc = decodeURIComponent(desc);
     wx.config({
     debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
     appId: appId, // 必填，公众号的唯一标识
     timestamp:timestamp, // 必填，生成签名的时间戳
     nonceStr: nonceStr, // 必填，生成签名的随机串
     signature: signature,// 必填，签名，见附录1
     jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
     });
     wx.ready(function(){
     //分享到朋友圈
     wx.onMenuShareTimeline({
     title: title, // 分享标题
     link: getUrl, // 分享链接
     imgUrl: imgUrl, // 分享图标
     success: function () {
     // 用户确认分享后执行的回调函数
     },
     cancel: function () {
     // 用户取消分享后执行的回调函数
     }
     });
     //分享给朋友
     wx.onMenuShareAppMessage({
     title: title, // 分享标题
     desc: desc, // 分享描述
     link: getUrl, // 分享链接
     imgUrl: imgUrl, // 分享图标
     type: '', // 分享类型,music、video或link，不填默认为link
     dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
     success: function () {
     // 用户确认分享后执行的回调函数
     },
     cancel: function () {
     // 用户取消分享后执行的回调函数
     }
     });
     });
     }*/


    getData.getJson({
        page:"content",
        inter:"getArticleInfo",
        loading:true,
        data:{id:contentid,token:token},
        callback:function(data){
            if(!data){
                components.alert("服务器出错!");
            }
            if(data.code=="2000"){
                // gm.pul.setTitle(data.contentTitle)
                obj_text_doc = data;
                /*var obj = {
                 "title":data.contentTitle,
                 "desc":data.contentTitle,
                 "link":gm.basePath + "../informationfordetails.html?contentUuid=" + contentid
                 };*/
                var getdetimg=gm.common.isObjUsable(data.value.iamgeUrl);
                getdetimg=getdetimg?window._interfaceImgPath+""+data.value.iamgeUrl:"../imgs/patientLogo.png";
                if(gm.common.isWeiXin()){
                    gm.common.userShare({
                        title:data.value.contentTitle,
                        imgUrl:getdetimg,
                        desc:data.value.intro,
                        url:getUrl
                    });//分享调用
                }


                $(".js_introduce").html("<h2>"+data.value.contentTitle + "</h2>");
                $(".js_introduce").append("<p>作者：" + (data.value.author || "无") + " <b>来源：" + (data.value.source || "未知") +"</b></p>");
                $(".js_introduce").append('<p class="ond"><i class="sj">'+data.value.createTime+'</i><b></b></p>');
                var contenNode=data.value.contentNote;
                if(contenNode==undefined ||contenNode==null)
                    contenNode="";
                

                $(".thearticley").html(data.value.introduction || "");

                $(".thearticley table").css({
                    width:"100%"
                });
                var collectRule=gm.para.get(window.location.href,"collectRule");
                var fontsize ="1.53rem";
                $(".theauthor_introduce .thearticley p,.theauthor_introduce .thearticley span").css('font-size',fontsize);


                $(".fx_share").bind({
                    touchend:function(){
                        //判断是否登录
                        if(!gm.user.isLoginDoctor()){
                            gm.pul.toUrl('goodm://login');
                            return;
                        }
                        var _ = $(this);
                        var p = _.parent().parent();
                        var _shareUuid = $(this).parents("li").attr("contextuuid");
                        var _shareType = $(this).parents("ul").attr("data");

                        var obj = {
                            title:$(".js_introduce h2").html(),//获取文章title
                            desc:p.find(".asbg .videomz h2 a").html(),//获取文章desc
                            img:p.find("img").attr("src"),//获取文章img
                            link:gm.basePath + "/html/thedoctorinformation/informationfordetails.shtml?contentUuid=" + gm.para.get("contentuuid")
                        };

                        gm.share(obj,function(){
                            /*getData.getJson({
                             page:"doctor",
                             inter:"addDoctorShare",
                             data:{contentUuid:contentUuid,doctorUuid:gm.user.getDoctor()},
                             callback:function(data){	}
                             });*/
                        });
                    }
                });
            }else{
                components.alert(data.message);
            }
        }
    });


    gm.pul.returnurl=function(){
        if(gm.para.get(window.location.href,"from")=="user")
            gm.pul.toUrl('/html/follow_up/toolbox/clinical_scale.shtml');
        else if(gm.para.get(window.location.href,"from")=="collection")
            gm.pul.toUrl('/html/user/my_collection.shtml?from=collection');
        else if(gm.para.get(window.location.href,"from")=="patientrefer")
            gm.pul.toUrl('patient/refer/refer_soul.shtml');
        else
            gm.pul.toUrl('/html/thedoctorinformation/index.shtml');
    };





    /*
     gm.my_task.tanchu=function () {
     //未登录情况无法分享
     if (!checkLogin()) {
     gm.pul.toUrl("goodm://login");
     return;
     }

     var _ = $(this);
     var p = _.parent().parent();
     var _shareUuid = gm.para.get(window.location.href, "contentUuid");
     var _shareType = $(this).parents("ul").attr("data");
     var _title = "";
     var _img = "";
     if (obj_text_doc) {
     _img = obj_text_doc.img;
     _title = obj_text_doc.contentTitle;
     }
     var obj = {
     title: _title,//获取文章title
     desc: _title,//获取文章desc
     img: _img,//获取文章img
     link: window._interfacePath + "/html/thedoctorinformation/informationfordetails.shtml?contentUuid=" + gm.para.get(window.location.href, "contentUuid")
     };

     gm.share(obj, function () {
     $.getDate({
     page: "doctor",
     inter: "addDoctorShare",
     data: {contentUuid: contentUuid, doctorUuid: gm.user.getDoctor()},
     callback: function (data) {
     }
     });
     });
     }*/
});
